<template>
  <div>
    <el-table :data="tableData">
      <el-table-column prop="action.id" label="订单序号"></el-table-column>
      <el-table-column prop="action.buyTime" label="下单时间" :formatter="formatData"></el-table-column>
      <el-table-column prop="action.result" label="订单状态">
        <template  #default="scope">
            {{scope.row.action.result == '0' ? "交易失败" : scope.row.action.result == '1' ? "交易成功": 
            scope.row.action.result == '2' ? "等待确认" :scope.row.action.result == '5' ? "已发货" :''}}
          </template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
        <el-button @click="sureorder(scope.row)">下一步</el-button>
        <el-button @click="removeorder(scope.row)">取消</el-button>
        <el-button @click="open">售后</el-button>
      </template>
      </el-table-column>
    </el-table>

    <el-dialog v-model="changeInfo" title="售后申请" :before-close="close">
      <el-form ref="form" :model="userChange" label-width="120px">
        <el-form-item class="item" label="标题:" prop="Password">
          <el-input
              type="password"
              placeholder="标题"
              show-password
          />
        </el-form-item>
        <el-form-item class="item" label="出现问题:" prop="address">
          <el-input
              type="address"
              placeholder="描述"
          />
        </el-form-item>
        <el-form-item class="item" label="图片:" prop="tel">
          <el-upload
                v-model:file-list="fileList"
                class="upload-demo"
                action="#"
                multiple
                accept=".jpg,.jpeg,.png,.JPG,.JPEG"
                :auto-upload="false"
                :on-remove="handleRemove"
                :limit="3"
                :on-exceed="handleExceed"
            >
              <el-button type="primary">点击上传图片</el-button>
              <template #tip>
                <div class="el-upload__tip">
                  jpg/png files with a size less than 500KB.
                </div>
              </template>
            </el-upload>
        </el-form-item>
        <el-form-item class="submit">
          <el-button type="primary" @click="change">确认</el-button>
          <el-button type="primary" @click="change">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import request from "@/utils/request";


export default {
  name: "OrderHistory",
  data(){
    
    return{
      tableData:[
      ],
      changeInfo: false,
      action: {},
      goods: {},
      user: {}

    }
  },

  methods:{
formatData(row, column, cellValue, index){
		
		//把传过来的日期进行回炉重造一下，又创建了一个js的 Date对象，进行重新构造，转为String字符串
		//最终返回 s 就可以了
		var s =	new Date(cellValue).toLocaleString();
	return s;
 },   
    sureorder(data){
      request.get("http://localhost:8087/order/sendOutwaitingForReception?tradeid="+data.action.id).then(res => {
        if (res.flag)                    {
          this.tableData = res.data['order2s']
          this.user = res.data['user']
          this.$message({
            type: 'success',
            message: res.msg
          });
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    removeorder(row){
      request.get("http://localhost:8087/order/CancelTrad?id="+row.action.id+"&goodsid="+row.action.goodsId).then(res => {
        if (res.flag) {
          this.tableData = res.data['order2s']
          this.user = res.data['user']
          this.$message({
            type: 'success',
            message: res.msg
          });
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    getOrders() {
      request.get("http://localhost:8087/order/viewOrders").then(res => {
        if (res.flag) {
          this.tableData = res.data['order2s']
          this.user = res.data['user']
          this.$message({
            type: 'success',
            message: res.msg
          });
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    Showorder(data){
      this.action = data.action
      this.goods = data.goods
      this.readorder=true;
    },
    open() {
      this.changeInfo = true;
    },
    change(){
      this.changeInfo = false;
  },
  },
  created() {
    this.getOrders()
  }
}
</script>

<style scoped>
.div2{
  background-size: 100% ;
  float: left;
  margin-top: -200px;
}
.b3{
  margin-bottom: 20px;
}
.dialog1{
  z-index: 2;
}
</style>
